﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO;
using Newtonsoft.Json;

namespace YiDingCanWp7
{
    public partial class ShopDetail : PhoneApplicationPage
    {
        string shopid = string.Empty;
        string url = BaseConfig.BaseUrl+"/Shop/ShopForMobile?shopid={0}";
        public ShopDetail()
        {
            InitializeComponent();

    
        }
        
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (this.NavigationContext.QueryString.ContainsKey("shopid"))
            {
                shopid = this.NavigationContext.QueryString["shopid"];
            }
            var webClient = new WebClient();
            webClient.OpenReadAsync(new Uri(string.Format(url, shopid)));
            webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
    
        }
        void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            using (var reader = new StreamReader(e.Result))
            {
                var returnStrs = reader.ReadToEnd();
                ShopDetailDTO shop = JsonConvert.DeserializeObject<ShopDetailDTO>(returnStrs);
                ApplicationTitle.Text = shop.title;
            }
        }
    }
}